package net.hn.hnms.biz.equipment.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import net.hn.hnms.biz.equipment.domain.CoalMineSysPointPo;
import net.hn.hnms.biz.equipment.domain.DrainageHisPo;
import net.hn.hnms.biz.equipment.domain.DrainageNowPo;
import net.hn.hnms.biz.equipment.domain.dto.*;
import net.hn.hnms.biz.equipment.domain.vo.ChartDateVo;
import net.hn.hnms.biz.equipment.domain.vo.HisVo;
import net.hn.hnms.biz.equipment.domain.vo.NowVo;
import net.hn.hnms.biz.equipment.domain.vo.PointHistoryListVo;
import net.hn.hnms.biz.equipment.mapper.CoalMineSysPointMapper;
import net.hn.hnms.biz.equipment.mapper.DrainageHisMapper;
import net.hn.hnms.biz.equipment.mapper.DrainageNowMapper;
import net.hn.hnms.biz.equipment.service.CoalMineSysPointService;
import net.hn.hnms.biz.equipment.service.DrainageService;
import net.hn.hnms.sys.common.core.domain.ResponsePage;
import net.hn.hnms.sys.common.core.utils.StringUtils;
import net.hn.hnms.sys.common.mybatis.core.page.PageQuery;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

@Service
public class DrainageServiceImpl implements DrainageService {
    @Resource
    private CoalMineSysPointMapper coalMineSysPointMapper;
    @Resource
    private DrainageNowMapper drainageNowMapper;
    @Resource
    private DrainageHisMapper drainageHisMapper;
    @Resource
    private CoalMineSysPointService coalMineSysPointService;


    /**
     * 分页条件查询实时数据
     *
     * @param pageQuery
     * @param nowDTO
     * @return
     */
    @Override
    public ResponsePage<NowVo> pageNowList(PageQuery pageQuery, NowDto nowDTO) {
        pageQuery.setPageNum(pageQuery.getPageNum() >= 1 ? pageQuery.getPageNum() * pageQuery.getPageSize():0);

        // 所属设备
        // 设备位置 去掉“泵房”三个字
        String deviceLocation = nowDTO.getDeviceLocation();
        nowDTO.setDeviceLocation(StringUtils.isNotEmpty(deviceLocation)?deviceLocation.replace("泵房", ""):null);

        List<SynergiaSysPointDto> list=coalMineSysPointMapper.selectDrainagePageList(pageQuery.getPageSize(), pageQuery.getPageNum(), nowDTO);
        if (list.isEmpty()) {
            return new ResponsePage<>(new ArrayList(), 0);
        }
        List<NowVo> collect = list.stream().map(t -> {
            NowVo nowVo = new NowVo();
            //测点编码
            nowVo.setPointCode(t.getPointCode());
            //所属设备
            nowVo.setCategory(t.getDeviceName());
            //设备位置
            nowVo.setDeviceLocation(t.getApiPage() );
            //测点名称
            nowVo.setPonitName(t.getApiNameCn());
            //数值类型
            nowVo.setValueType(coalMineSysPointService.valueTypeTransitionString(t.getValueType()));
            //检测值
            nowVo.setValue(t.getPointValue());
            //数值单位
            nowVo.setValueUnit(StringUtils.isNotEmpty(t.getSensorUnit())?t.getSensorUnit():"-");
            //检测说明
            nowVo.setValueContent(t.getRemark());
            //数据质量
            nowVo.setDataUality(coalMineSysPointService.dataUalityTransitionString(t.getPointStatus()));
            //数据时间
            nowVo.setDateTime(t.getDataTime());
            return nowVo;
        }).collect(Collectors.toList());
        return new ResponsePage<>(collect,list.get(0).getTotal());

    }
//
//    /**
//     * 分页条件查询报警明细
//     *
//     * @param pageQuery
//     * @param abnormalDTO
//     * @return
//     */
//    @Override
//    public TableDataInfo<FanHisPo> pageAbnormalInfo(PageQuery pageQuery, AbnormalDto abnormalDTO) {
////        Date startTime = new Date();
////        Date endTime = new Date();
////        try {
////            //获取开始时间
////            Date startdate = null;
////            Date endDate = null;
////            if (abnormalDTO.getEndTime() != null && abnormalDTO.getStartTime() != null) {
////                startTime = abnormalDTO.getStartTime();
////                endTime = abnormalDTO.getEndTime();
////                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
////                String startTimeString = simpleDateFormat.format(startTime);
////                String endTimeString = simpleDateFormat.format(endTime);
////                startdate = DateUtils.parseDate(startTimeString + " 00:00:00", "yyyy-MM-dd HH:mm:ss");
////                endDate = DateUtils.parseDate(endTimeString + " 23:59:59", "yyyy-MM-dd HH:mm:ss");
////            }
////            Page<SynergiadataAbnormalPo> synergiadataAbnormalPoPage = synergiadataAbnormalMapper.selectPage(pageQuery.build(), new LambdaQueryWrapper<SynergiadataAbnormalPo>()
////                    //统计类型
////                    // TODO
////                    //报警类型
////                    .eq(StringUtils.isNotBlank(abnormalDTO.getExceptionType()), SynergiadataAbnormalPo::getExceptionType, abnormalDTO.getExceptionType())
////                    //异常开始时间
////                    .between(abnormalDTO.getStartTime() != null && abnormalDTO.getEndTime() != null, SynergiadataAbnormalPo::getStartTime, startdate, endDate)
////                    //异常结束时间
////                    .between(abnormalDTO.getStartTime() != null && abnormalDTO.getEndTime() != null, SynergiadataAbnormalPo::getEndTime, startdate, endDate));
////            if (synergiadataAbnormalPoPage.getRecords().isEmpty()) {
////                new TableDataInfo<>();
////            }
////            return TableDataInfo.build(synergiadataAbnormalPoPage);
////        } catch (Exception e) {
////            throw new HuaNengException(Constants.FAIL, "未知错误");
////        }
//        return null;
//    }


    /**
     * 分页条件查询历史数据
     *
     * @param pageQuery
     * @param hisDTO
     * @return
     */
    @Override
    public ResponsePage<HisVo> pageHistoryInfo(PageQuery pageQuery, HisDto hisDTO) {
        pageQuery.setPageNum(pageQuery.getPageNum() >= 1 ? pageQuery.getPageNum() * pageQuery.getPageSize():0);

        // 所属设备
        // 设备位置 去掉“工作面”三个字
        String deviceLocation = hisDTO.getDeviceLocation();
        hisDTO.setDeviceLocation(StringUtils.isNotEmpty(deviceLocation)?deviceLocation.replace("工作面", ""):null);


        List<SynergiaSysPointDto> list=coalMineSysPointMapper.selectDrainageHisPageList(pageQuery.getPageSize(), pageQuery.getPageNum(), hisDTO);
        if (list.isEmpty()) {
            return new ResponsePage<>(new ArrayList(), 0);
        }
        List<HisVo> collect = list.stream().map(t -> {
            HisVo hisVo = new HisVo();
            //测点编码
            hisVo.setPointCode(t.getPointCode());
            //所属设备
            hisVo.setCategory(t.getDeviceName());
            //设备位置
            hisVo.setDeviceLocation(t.getApiPage() );
            //测点名称
            hisVo.setPonitName(t.getApiNameCn());
            //数值类型
            hisVo.setValueType(coalMineSysPointService.valueTypeTransitionString(t.getValueType()));
            //检测值
            hisVo.setValue(t.getPointValue());
            //数值单位
            hisVo.setValueUnit(StringUtils.isNotEmpty(t.getSensorUnit())?t.getSensorUnit():"-");
            //检测说明
            hisVo.setValueContent(t.getRemark());
            //数据质量
            hisVo.setDataUality(coalMineSysPointService.dataUalityTransitionString(t.getPointStatus()));
            //数据时间
            hisVo.setDateTime(t.getDataTime());
            return hisVo;
        }).collect(Collectors.toList());
        List<HisVo> collectVo = collect.stream().sorted(Comparator.comparing(HisVo::getDateTime).reversed()).collect(Collectors.toList());
        return new ResponsePage<>(collectVo,list.get(0).getTotal());
    }

    /**
     * 获取所属设备下拉列表
     * @return
     */
    @Override
    public List<String> categoryList(String mineCode) {
        LambdaQueryWrapper<CoalMineSysPointPo> coalMineSysPointPoLambdaQueryWrapper = new LambdaQueryWrapper<>();
        //查询所有协同开采的设备
        coalMineSysPointPoLambdaQueryWrapper.like(CoalMineSysPointPo::getApiCategory, "drainage");
        coalMineSysPointPoLambdaQueryWrapper.eq(StringUtils.isNotEmpty(mineCode),CoalMineSysPointPo::getMineCode, mineCode);
        List<CoalMineSysPointPo> coalMineSysPointPoList = coalMineSysPointMapper.selectList(coalMineSysPointPoLambdaQueryWrapper);
        List<String> collect = coalMineSysPointPoList.stream().map(t -> {
            String s = new String();
            s = t.getDeviceName();
            return s;
        }).distinct().collect(Collectors.toList());
        return collect;
    }

    /**
     * 获取设备位置下拉列表
     * @return
     */
    @Override
    public List<String> deviceLocaltionList(String mineCode) {
        LambdaQueryWrapper<CoalMineSysPointPo> coalMineSysPointPoLambdaQueryWrapper = new LambdaQueryWrapper<>();
        //查询所有协同开采的设备
        coalMineSysPointPoLambdaQueryWrapper.like(CoalMineSysPointPo::getApiCategory, "drainage");
        coalMineSysPointPoLambdaQueryWrapper.eq(StringUtils.isNotEmpty(mineCode),CoalMineSysPointPo::getMineCode, mineCode);
        List<CoalMineSysPointPo> coalMineSysPointPoList = coalMineSysPointMapper.selectList(coalMineSysPointPoLambdaQueryWrapper);
        List<String> collect = coalMineSysPointPoList.stream().map(t -> {
            String s = new String();
            s = t.getApiPage();
            return s;
        }).distinct().collect(Collectors.toList());
        return collect;
    }

    /**
     * 获取水泵房排水量的数据
     * @return
     */
    @Override
    public BigDecimal getDrainAwayWater(String mineCode) {
        //获取重大设备 主排水的实时数据 排水量 是所有的管路流量相加

        // 获取水泵房的排水数据

        //20230217 issue:每个矿采集管路流量的名字都不一样，更改从配置表中获取固定的管路流量记录，从记录中获取配置的tag值，再从实时排水表中读取
        //获取配置表中的所有管路流量
        LambdaQueryWrapper<CoalMineSysPointPo> coalMineSysPointPoLambdaQueryWrapper = new LambdaQueryWrapper<>();
        //设置煤矿编码
        coalMineSysPointPoLambdaQueryWrapper.eq(StringUtils.isNotBlank(mineCode), CoalMineSysPointPo::getMineCode, mineCode);
        coalMineSysPointPoLambdaQueryWrapper.like(CoalMineSysPointPo::getApiNameCn, "管路流量");
        //拿到管路流量的记录列表
        List<CoalMineSysPointPo> coalMineSysPointPos = coalMineSysPointMapper.selectList(coalMineSysPointPoLambdaQueryWrapper);
        //筛选过滤为空的tag值
        List<String> collectTagList = coalMineSysPointPos.stream().filter(t -> {
            return t.getPointTag()!=null && t.getPointTag()!="";
        }).map(t -> {
            return t.getPointTag();
        }).collect(Collectors.toList());
        //通过TagList查询排水实时表中的记录

        List<DrainageNowPo> drainageNowPoList = drainageNowMapper.selectList(
                new LambdaQueryWrapper<DrainageNowPo>()
                        .in(DrainageNowPo::getPointCode, collectTagList)
                        .eq(StringUtils.isNotBlank(mineCode), DrainageNowPo::getMineCode, mineCode));

        if (drainageNowPoList.isEmpty()) {
            return new BigDecimal(0);
        }
        BigDecimal bigDecimal = new BigDecimal(0);
        for (DrainageNowPo drainageNowPo : drainageNowPoList) {
            bigDecimal = bigDecimal.add(drainageNowPo.getPointValue());
        }
        return bigDecimal;
    }

    /**
     * 获取水泵房排水量今日累计量的数据
     * @return
     */
    @Override
    public BigDecimal getTodayAddDrainAwayWater(String mineCode) {
        //获取重大设备 主排水的实时数据 排水量 是所有的管路流量相加

//        List<DrainageNowPo> drainageNowPoList = drainageNowMapper.selectList(new LambdaQueryWrapper<DrainageNowPo>().like(DrainageNowPo::getPointCode, "累计流量"));
//        if (drainageNowPoList.isEmpty()) {
//            return new BigDecimal(0);
//        }
//        BigDecimal bigDecimal = new BigDecimal(0);
//        for (DrainageNowPo drainageNowPo : drainageNowPoList) {
//            bigDecimal = bigDecimal.add(new BigDecimal(drainageNowPo.getPointValue()));
//        }
//        List<String> list = new ArrayList<>();
//        list.add("NewSite_ZPS1050_泵房1050管路流量1");
//        list.add("NewSite_ZPS1050_泵房1050管路流量2");
//        list.add("NewSite_ZPS860_管路流量1");
//        list.add("NewSite_ZPS860_管路流量2");

        //20230217 issue:每个矿采集管路流量的名字都不一样，更改从配置表中获取固定的管路流量记录，从记录中获取配置的tag值，再从实时排水表中读取
        //获取配置表中的所有管路流量
        if ("150781013671".equals(mineCode)) {
            //灵露煤矿煤矿则直接查询所有管路单日累计量
            List<DrainageNowPo> drainageNowPos = drainageNowMapper.selectList(new LambdaQueryWrapper<DrainageNowPo>()
                    .likeLeft(DrainageNowPo::getPointCode, "管路流量单日累计"));
            BigDecimal bigDecimal = new BigDecimal(0);
            for (DrainageNowPo t : drainageNowPos) {
//                bigDecimal = bigDecimal.add(new BigDecimal((String) (t.getPointValue() == null ? 0 : t.getPointValue())));
                if (t.getPointValue()!= null) {
                    bigDecimal = bigDecimal.add(t.getPointValue());
                } else {
                    bigDecimal = bigDecimal.add(BigDecimal.ZERO);
                }
            }
            return bigDecimal;
        } else {
            //其他煤矿
            LambdaQueryWrapper<CoalMineSysPointPo> coalMineSysPointPoLambdaQueryWrapper = new LambdaQueryWrapper<>();
            //设置煤矿编码
            coalMineSysPointPoLambdaQueryWrapper.eq(StringUtils.isNotBlank(mineCode), CoalMineSysPointPo::getMineCode, mineCode);
            coalMineSysPointPoLambdaQueryWrapper.like(CoalMineSysPointPo::getApiNameCn, "管路流量");
            //拿到管路流量的记录列表
            List<CoalMineSysPointPo> coalMineSysPointPos = coalMineSysPointMapper.selectList(coalMineSysPointPoLambdaQueryWrapper);
            //筛选过滤为空的tag值
            List<String> collectTagList = coalMineSysPointPos.stream().filter(t -> {
                return t.getPointTag() != null && t.getPointTag() != "";
            }).map(t -> {
                return t.getPointTag();
            }).collect(Collectors.toList());
            //通过TagList查询排水实时表中的记录
            BigDecimal bigDecimal = new BigDecimal(0);
            for (String s : collectTagList) {
                Long aLong = drainageNowMapper.selectSumAllList(s, mineCode);
                bigDecimal = bigDecimal.add(new BigDecimal(aLong == null ? 0 : aLong));
            }
            //从凌晨到现在的管道流量sum之和


            return bigDecimal;
        }
    }

    /**
     * 排水系统-开关信息
     * @param pump
     * @param mineCode
     * @return
     */
    @Override
    public Map<String, Integer> switchInfo(String pump, String mineCode) {
        //获取配置表中泵房的所有的开关信息
        LambdaQueryWrapper<CoalMineSysPointPo> queryWrapper = new LambdaQueryWrapper<>();
        //煤矿编码
        queryWrapper.eq(StringUtils.isNotBlank(mineCode), CoalMineSysPointPo::getMineCode, mineCode);
        //泵房名称
        queryWrapper.like(StringUtils.isNotBlank(pump), CoalMineSysPointPo::getApiPage, pump);
        //获取所有的开关信息
        queryWrapper.eq(CoalMineSysPointPo::getApiName, "runningState");
        //限定为排水系统
        queryWrapper.like(CoalMineSysPointPo::getApiCategory, "drainage");
        List<CoalMineSysPointPo> coalMineSysPointPos = coalMineSysPointMapper.selectList(queryWrapper);
        int open = 0;
        int stop = 0;
        Map<String, Integer> stringIntegerHashMap = new HashMap<>();
        for (CoalMineSysPointPo t : coalMineSysPointPos) {
            //判断tag值
            if (t.getPointTag() != null) {
                DrainageNowPo drainageNowPo = drainageNowMapper.selectOne(new LambdaQueryWrapper<DrainageNowPo>()
                        .eq(DrainageNowPo::getPointCode, t.getPointTag())
                        .eq(StringUtils.isNotBlank(mineCode), DrainageNowPo::getMineCode, mineCode));
                //根据tag值查询排水实时表
                if (drainageNowPo != null) {
                    Long pointValue = drainageNowPo.getPointValue().longValue();
                    //不为零则开启
                    if (pointValue != 0) {
                        open = open + 1;
                    } else {
                        stop = stop + 1;
                    }

                    //tag 有配置但是未查到 测判断为关闭
                } else {
                    stop = stop + 1;
                }
                //tag 无值 则判断为关闭
            } else {
                stop = stop + 1;
            }
        }
        stringIntegerHashMap.put("open", open);
        stringIntegerHashMap.put("stop", stop);
        return stringIntegerHashMap;
    }

    /**
     * 排水系统-主副水位
     * @param pump
     * @param mineCode
     * @return
     */
    @Override
    public Map<String, Float> waterLevelInfo(String pump, String mineCode) {
        //获取配置表中泵房的所有的开关信息
        LambdaQueryWrapper<CoalMineSysPointPo> queryWrapper = new LambdaQueryWrapper<>();
        //煤矿编码
        queryWrapper.eq(StringUtils.isNotBlank(mineCode), CoalMineSysPointPo::getMineCode, mineCode);
        //泵房名称
        queryWrapper.like(StringUtils.isNotBlank(pump), CoalMineSysPointPo::getApiPage, pump);
        //获取所有的主副水仓信息
        queryWrapper.in(CoalMineSysPointPo::getApiName, "sump01WaterLevelValue","sump02WaterLevelValue");
        //限定为排水系统的水仓
        queryWrapper.like(CoalMineSysPointPo::getApiCategory, "drainage-sump");
        List<CoalMineSysPointPo> coalMineSysPointPos = coalMineSysPointMapper.selectList(queryWrapper);
        Map<String, Float> stringIntegerHashMap = new HashMap<>();
        for (CoalMineSysPointPo coalMineSysPointPo : coalMineSysPointPos) {
            if ("sump01WaterLevelValue".equals(coalMineSysPointPo.getApiName())) {
                //主水仓
                if (coalMineSysPointPo.getPointTag() != null) {
                    DrainageNowPo drainageNowPo = drainageNowMapper.selectOne(new LambdaQueryWrapper<DrainageNowPo>()
                            .eq(StringUtils.isNotBlank(mineCode), DrainageNowPo::getMineCode, mineCode)
                            .eq(DrainageNowPo::getPointCode, coalMineSysPointPo.getPointTag()));
                    if (drainageNowPo != null) {
                        stringIntegerHashMap.put("主", drainageNowPo.getPointValue().floatValue());
                    } else {
                        stringIntegerHashMap.put("主", 0F);
                    }
                    //如果tag值为空 则直接赋值零
                } else {
                    stringIntegerHashMap.put("主", 0F);
                }
            }
            if ("sump02WaterLevelValue".equals(coalMineSysPointPo.getApiName())) {
                //副水仓
                if (coalMineSysPointPo.getPointTag() != null) {
                    DrainageNowPo drainageNowPo = drainageNowMapper.selectOne(new LambdaQueryWrapper<DrainageNowPo>()
                            .eq(StringUtils.isNotBlank(mineCode), DrainageNowPo::getMineCode, mineCode)
                            .eq(DrainageNowPo::getPointCode, coalMineSysPointPo.getPointTag()));
                    if (drainageNowPo != null) {
                        stringIntegerHashMap.put("副", drainageNowPo.getPointValue().floatValue());
                    } else {
                        stringIntegerHashMap.put("副", 0F);
                    }
                    //如果tag值为空 则直接赋值零
                } else {
                    stringIntegerHashMap.put("副", 0F);
                }
            }
        }
        return stringIntegerHashMap;
    }
    /**
     * 条件查询历史数据测点曲线
     * @param pointDto
     * @return
     */
    @Override
    public ChartDateVo pointHistoryCurve(PointDto pointDto) {
        //1天内 日期间隔不做处理
        //1~3天 日期间隔5分钟 取最大值
        //3天~1月  日期间隔1小时 取最大值
        //超过1月  返回前端消息，查询时间范围为一个月

        //查询得数据集合
        List<DrainageHisPo> coalflowHisPos = null;
        //返回得数据集合Vo
        ChartDateVo chartDateVo = new ChartDateVo();
        List<Date> dateList = new ArrayList<>();
        List<BigDecimal> bigDecimalList = new ArrayList<>();


        if (pointDto.getEndTime().getTime() - pointDto.getStartTime().getTime() <= 3600 * 24 * 1 * 1000L) {
            LambdaQueryWrapper<DrainageHisPo> queryWrapper = new LambdaQueryWrapper<>();
            //一天内得数据
            queryWrapper.ge(DrainageHisPo::getDataTime,pointDto.getStartTime());
            //结束时间
            queryWrapper.le(pointDto.getEndTime() != null, DrainageHisPo::getDataTime, pointDto.getEndTime());
            queryWrapper.eq(DrainageHisPo::getPointCode, pointDto.getPointCode());

            //煤矿编码
            queryWrapper.eq(StringUtils.isNotEmpty(pointDto.getMineCode()),DrainageHisPo::getMineCode,pointDto.getMineCode());
            coalflowHisPos = drainageHisMapper.selectList(queryWrapper);
        } else if (pointDto.getEndTime().getTime() - pointDto.getStartTime().getTime() <= 3600 * 24 * 3 * 1000L) {
            //三天内得数据
            List<ChartDto> chartDtoList= drainageHisMapper.selectOneDayList(pointDto);
            for (ChartDto chartDto : chartDtoList) {
                dateList.add(chartDto.getTime());
                bigDecimalList.add(chartDto.getValue());
            }
            chartDateVo.setDate(dateList);
            chartDateVo.setValue(bigDecimalList);
            return chartDateVo;
        } else if (pointDto.getEndTime().getTime() - pointDto.getStartTime().getTime() <= 3600 * 24 * 31 * 1000L) {
            //1月内得数据
            List<ChartDto> chartDtoList= drainageHisMapper.selectOneMonthList(pointDto);
            for (ChartDto chartDto : chartDtoList) {
                dateList.add(chartDto.getTime());
                bigDecimalList.add(chartDto.getValue());
            }
            chartDateVo.setDate(dateList);
            chartDateVo.setValue(bigDecimalList);
            return chartDateVo;
        }

        if (coalflowHisPos.isEmpty()) {

            chartDateVo.setDate(dateList);
            chartDateVo.setValue(bigDecimalList);
            return chartDateVo;
        }
        //list 降序排列
        List<DrainageHisPo> collect = coalflowHisPos.stream().sorted(Comparator.comparing(DrainageHisPo::getDataTime).reversed()).collect(Collectors.toList());
        for (DrainageHisPo coalflowHisPo : collect) {
            dateList.add(coalflowHisPo.getDataTime());
            bigDecimalList.add(new BigDecimal(coalflowHisPo.getPointValue()));
        }
        chartDateVo.setDate(dateList);
        chartDateVo.setValue(bigDecimalList);
        return chartDateVo;
    }

    /**
     * 条件查询历史数据测点列表
     * @param pointDto
     * @return
     */
    @Override
    public List<PointHistoryListVo> pointHistoryList(PointDto pointDto) {
        //1天内 日期间隔不做处理
        //1~3天 日期间隔5分钟 取最大值
        //3天~1月  日期间隔1小时 取最大值
        //超过1月  返回前端消息，查询时间范围为一个月

        //查询得数据集合
        List<DrainageHisPo> coalflowHisPos = null;

        String stateCode = "1";
        if (pointDto.getEndTime().getTime() - pointDto.getStartTime().getTime() <= 3600 * 24 * 1 * 1000L) {
            LambdaQueryWrapper<DrainageHisPo> queryWrapper = new LambdaQueryWrapper<>();
            //一天内得数据
            queryWrapper.ge(DrainageHisPo::getDataTime,pointDto.getStartTime());
            //结束时间
            queryWrapper.le(pointDto.getEndTime() != null, DrainageHisPo::getDataTime, pointDto.getEndTime());
            queryWrapper.eq(DrainageHisPo::getPointCode, pointDto.getPointCode());

            //煤矿编码
            queryWrapper.eq(StringUtils.isNotEmpty(pointDto.getMineCode()),DrainageHisPo::getMineCode,pointDto.getMineCode());
            coalflowHisPos = drainageHisMapper.selectList(queryWrapper);
        } else if (pointDto.getEndTime().getTime() - pointDto.getStartTime().getTime() <= 3600 * 24 * 3 * 1000L) {
            //三天内得数据
            List<ChartDto> chartDtoList= drainageHisMapper.selectOneDayList(pointDto);
            List<PointHistoryListVo> collect = chartDtoList.stream().map(t -> {
                PointHistoryListVo pointHistoryListVo = new PointHistoryListVo();
                pointHistoryListVo.setDate(t.getTime());
                pointHistoryListVo.setValue(t.getValue());
                pointHistoryListVo.setState(stateCode.equals(t.getState()) ? "正常" : "异常");
                pointHistoryListVo.setStateCode(t.getState());
                return pointHistoryListVo;
            }).collect(Collectors.toList());
            return collect;
        } else if (pointDto.getEndTime().getTime() - pointDto.getStartTime().getTime() <= 3600 * 24 * 31 * 1000L) {
            //1月内得数据
            List<ChartDto> chartDtoList= drainageHisMapper.selectOneMonthList(pointDto);
            List<PointHistoryListVo> collect = chartDtoList.stream().map(t -> {
                PointHistoryListVo pointHistoryListVo = new PointHistoryListVo();
                pointHistoryListVo.setDate(t.getTime());
                pointHistoryListVo.setValue(t.getValue());
                pointHistoryListVo.setState(stateCode.equals(t.getState()) ? "正常" : "异常");
                pointHistoryListVo.setStateCode(t.getState());
                return pointHistoryListVo;
            }).collect(Collectors.toList());
            return collect;
        }

        if (coalflowHisPos.isEmpty()) {
            return new ArrayList<>();
        }
        //list 降序排列
        List<DrainageHisPo> collect = coalflowHisPos.stream().sorted(Comparator.comparing(DrainageHisPo::getDataTime).reversed()).collect(Collectors.toList());
        List<PointHistoryListVo> collectVo = collect.stream().map(t -> {
            PointHistoryListVo pointHistoryListVo = new PointHistoryListVo();
            pointHistoryListVo.setDate(t.getDataTime());
            pointHistoryListVo.setValue(new BigDecimal(t.getPointValue()));
            pointHistoryListVo.setState(stateCode.equals(t.getPointStatus().toString()) ? "正常" : "异常");
            pointHistoryListVo.setStateCode(t.getPointStatus().toString());
            return pointHistoryListVo;
        }).collect(Collectors.toList());
        return collectVo;
    }

}
